<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>规则集信息新增</title>
<link href="../../static/plugin/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/plugin/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
<script src="../../static/plugin/easyui/jquery.min.js" type="text/javascript"></script>
<script src="../../static/plugin/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/plugin/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../ffres/dict/all.js" type="text/javascript"></script>
<script src="../../ffres/dict/city.js" type="text/javascript"></script>
<script src="../../ffres/dict/org.js" type="text/javascript"></script>
<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout">
	<form id="ff" method="post">
		<div class="esaas-info-title">规则集信息</div>
		<table class="esaas-info-add-table">
			<tr>
				<td width="15%" align="right">规则集编号：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="ruleCollId" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">规则集名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="ruleCollDesc" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">规则集类型：</td>
				<td width="35%"><select class="easyui-combobox"
					id="ruleCollType" name="ruleCollType"
					style="width: 100%; height: 25px;"
					data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:RULE_COLL_TYPE,onChange:ruleTypeOnChange">
				</select></td>
				<td width="15%" align="right">规则集版本：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="ruleCollVersion" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr class="specialApproval">
				<td width="15%" align="right">适用抵押物选择：</td>
				<td width="35%"><select class="easyui-combobox"
										id="adapterCustomDim1Select" name="adapterCustomDim1Select"
										style="width: 100%; height: 25px;"
										valueField="enname" textField="cnname"
										data-options="required:true,editable:false,data:RULE_MORT_SELECT,onChange:mortSelectOnChange">
				</select></td>
				<td width="15%" align="right">适用机构选择：</td>
				<td width="35%"><select class="easyui-combobox"
										id="adapterOrgNoSelect" name="adapterOrgNoSelect"
										style="width: 100%; height: 25px;"
										valueField="enname" textField="cnname"
										data-options="required:true,editable:false,data:RULE_ORG_SELECT,onChange:orgSelectOnChange">
				</select></td>
			</tr>
			<tr class="specialApproval">
				<td class="adapterCustomDim1Cls" width="15%" align="right">适用抵押物地址：</td>
				<td class="adapterCustomDim1Cls" width="35%"><select class="easyui-combobox"
										id="adapterCustomDim1" name="adapterCustomDim1"
										style="width: 100%; height: 50px;"
										valueField="enname" textField="cnname" groupField="parent"
										multiple="true" multiline="true"
										data-options="required:false,editable:false,data:CUSTOM_CITY">
				</select></td>
				<td class="adapterBlank" width="15%"></td>
				<td class="adapterBlank" width="35%"></td>
				<td class="adapterOrgNoCls" width="15%" align="right">适用机构：</td>
				<td class="adapterOrgNoCls" width="35%"><select class="easyui-combobox"
										id="adapterOrgNo" name="adapterOrgNo"
										style="width: 100%; height: 50px;"
										multiple="true" multiline="true"
										data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:CUSTOM_ORG">
				</select></td>
			</tr>
			<tr>
				<td width="15%" align="right">规则集状态：</td>
				<td width="35%"><select class="easyui-combobox"
					id="ruleCollState" name="ruleCollState"
					style="width: 100%; height: 25px;"
					data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:RULE_COLL_STATE">
				</select></td>
				<!--<td width="15%" align="right">创建用户：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="createUser" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>-->
			</tr>
		</table>
	</form>
	<div style="text-align: center; padding: 15px">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			onclick="submitForm()">&nbsp;保&nbsp;存&nbsp;</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>
	<script>

        var skipChangeEvent = false;
		$(function() {
            $('.specialApproval').hide();
            $('.adapterCustomDim1Cls').hide();
            $('.adapterOrgNoCls').hide();
            $('.adapterBlank').hide();
		});

        function submitForm() {
            var jsonData = $("#ff").serializeJson();
            if (jsonData.adapterOrgNo && !Array.isArray(jsonData.adapterOrgNo)) {
                jsonData.adapterOrgNo = [jsonData.adapterOrgNo];
			}
            if (jsonData.adapterCustomDim1 && !Array.isArray(jsonData.adapterCustomDim1)) {
                jsonData.adapterCustomDim1 = [jsonData.adapterCustomDim1];
            }
            if (jsonData.ruleCollType === '02') {
                // 等于特批
                $('#adapterCustomDim1Select').combobox({required:true})
                $('#adapterOrgNoSelect').combobox({required:true})
                skipChangeEvent = true;
                $('#adapterCustomDim1Select').combobox("setValue", jsonData.adapterCustomDim1Select);
                $('#adapterOrgNoSelect').combobox("setValue", jsonData.adapterOrgNoSelect);
                skipChangeEvent = false;
			} else {
                $('#adapterCustomDim1Select').combobox({required:false})
                $('#adapterOrgNoSelect').combobox({required:false})
                skipChangeEvent = true;
                $('#adapterCustomDim1Select').combobox("setValue", jsonData.adapterCustomDim1Select);
                $('#adapterOrgNoSelect').combobox("setValue", jsonData.adapterOrgNoSelect);
                skipChangeEvent = false;
			}
            if (!$('#ff').form('validate')) {
                return;
            }
            $.restfulPostJson('../../api/s/rule/coll/info', jsonData, function(data) {
				window.parent.reloadList();
			});
		};
		
		function closeForm() {
			window.parent.JLEUtil.closewin();
		}

		function ruleTypeOnChange(val, old) {
		    if (val === '02') {
		        // 特批审批大纲 显示 specialApproval
				$('.specialApproval').show();
			} else {
                $('.specialApproval').hide();
			}
		}

		function mortSelectOnChange(newValue, oldValue) {
            if (skipChangeEvent) {
                return;
            }
		    if (newValue === '1') {
		        //  指定城市
                $('.adapterCustomDim1Cls').show();
                $('.adapterBlank').hide();
                $('#adapterCustomDim1').combobox({required:true})
			} else {
                $('.adapterCustomDim1Cls').hide();
                $('.adapterBlank').show();
                $('#adapterCustomDim1').combobox({required:false})
			}
		}

		function orgSelectOnChange(newValue, oldValue) {
            if (skipChangeEvent) {
                return;
            }
		    if (newValue === '1') {
		        if($('#adapterCustomDim1Select').combobox('getValue') !== "1") {
                    $('.adapterBlank').show();
				}
		        //  指定机构
                $('.adapterOrgNoCls').show();
                $('#adapterOrgNo').combobox({required:true})
			} else {
                if($('#adapterCustomDim1Select').combobox('getValue') !== "1") {
                    $('.adapterBlank').hide();
                }
                $('.adapterOrgNoCls').hide();
                $('#adapterOrgNo').combobox({required:false})
			}
		}
	</script>
</body>
</html>